package com.zhongxiangspace.controller;

import com.zhongxiangspace.entity.BuildingsAttribute;
import com.zhongxiangspace.entity.County;
import com.zhongxiangspace.entity.House;
import com.zhongxiangspace.entity.OfficeBuildings;
import com.zhongxiangspace.entity.QueryAnalyzer;
import com.zhongxiangspace.entity.VO.QueryAnalyzerOffice;
import com.zhongxiangspace.service.CountyService;
import com.zhongxiangspace.service.HouseService;
import com.zhongxiangspace.service.OfficeBuildingService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import sun.java2d.pipe.AAShapePipe;

@Controller
public class BuildingListController {
    @Autowired
    private HouseService houseService;
    @Autowired
    private CountyService countyService;
    @Autowired
    private OfficeBuildingService officeBuildingService;

    @GetMapping({"lists/bu{id}"})
    public String detailsBu(Model model, @PathVariable("id") Integer id) {
        Map<String, Object> map = new HashMap();
        OfficeBuildings office = this.officeBuildingService.queryOne(id);
        map.put("office", office);
        BuildingsAttribute buildingsAttribute = this.officeBuildingService.queryAttr(office.getBuilding_id());
        map.put("buildingsAttribute", buildingsAttribute);
        County county = this.countyService.queryOne(office.getCounty_id());
        map.put("county", county);
        County trade_area = this.countyService.queryOne(office.getTrade_area_id());
        map.put("trade_area", trade_area);

        QueryAnalyzer buildingQueryAnalyzer = new QueryAnalyzer();
        buildingQueryAnalyzer.setShowCode(Integer.valueOf(1));
        buildingQueryAnalyzer.setHotCode(Integer.valueOf(1));
        List<Map<String, Object>> officeBuildingsList = this.officeBuildingService.queryOfficeBuilding(buildingQueryAnalyzer);
        map.put("officeBuildings", officeBuildingsList);

        QueryAnalyzerOffice queryAnalyzerOffice = new QueryAnalyzerOffice();
        queryAnalyzerOffice.setBuilding_id(office.getBuilding_id());
        List<House> houseList = this.houseService.queryBHList(queryAnalyzerOffice);
        map.put("houseList", houseList);
        model.addAttribute("data", map);
        return "list/office_detail_mobile";
    }
}
